// pages/select/select_list.js

var gmapi = require('../../utils/gameapi.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1,
    size: 5,
    maxnum: 10,
    sellist: [],
    seluserinfo: '',
    listleft: 0,
    listright: 1,
    phtoimg: "../imgs/toux.png",
    userInfo: 'hejing',
    level: '神童',
    ranking_list: '20',
    level_list: '2',
    have_money: '1',
    ranking_number: '120',
    ranking_money: '300',
    ranking_number4: '4',
    ranking_number5: '5',
    level2: '智者',
    level3: '常人',
    level4: '新手',
    number_t: '1',
    rankingType: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.getsellist()
  },
  getsellist: function() {
    var that = this;
    var rankingUrl = app.globalData.urlapi + '/splicingGame/rankingList';
    if (that.data.rankingType==2){
      rankingUrl = app.globalData.urlapi + '/splicingGame/rankingList2';
    }
    wx.request({
      url: rankingUrl,
      method: 'GET',
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization': app.globalData.token
      },
      data: {
        num: that.data.num,
        size: that.data.size
      },
      success: function(res) {
        console.log(res)
        if (res.data.code == 200) {
          if (that.data.num < res.data.data.rankingTotal / that.data.size) {
            that.setData({
              listright: 1
            })
          } else {
            that.setData({
              listright: 0
            })
          }
          if (that.data.num > 1) {
            that.setData({
              listleft: 1
            })
          } else {
            that.setData({
              listleft: 0
            })
          }
          that.setData({
            seluserinfo: res.data.data.userRanking,
            maxnum: res.data.data.rankingTotal / that.data.size,
            sellist: res.data.data.rankingList
          })
          console.log('授权成功:' + that.data.sellist)

        } else {
          console.log('授权失败');
          gmapi.gmgettoken();
        }
      }
    })
  },
  minuslist: function() {
    var that = this;
    if (that.data.num > 1) {
      that.setData({
        num: that.data.num - 1
      })
      that.getsellist();
    }
  },
  addlist: function() {
    var that = this;
    if (that.data.num < that.data.maxnum) {
      that.setData({
        num: that.data.num + 1
      })
      that.getsellist();
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  getlist: function() {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  radioChange: function(e) {
    var that = this;
    if (e.detail.value != that.data.rankingType) {
      this.setData({
        rankingType: e.detail.value,
        num: 1
      })
      that.getsellist()
    }
  }
})